package com.cloud.code.算法.栈;

import com.cloud.code.算法.动态数组.Array;

public class ArrayStack<E> implements Stack<E>{

    private static final int CAPACITY = 10;

    private Array<E> array ;

    public ArrayStack(){
        array = new Array<>(CAPACITY);
    }

    public ArrayStack(int capacity){
        array = new Array<>(capacity);
    }

    @Override
    public int getSize() {
        return array.getSize();
    }

    @Override
    public boolean isEmpty() {
        return getSize() == 0;
    }

    @Override
    public void push(E e) {
        array.addFast(e);
    }

    @Override
    public E pop() {
        return array.removeFast();
    }

    @Override
    public E peek() {
        return array.get(0);
    }

    @Override
    public String toString() {
        return "ArrayStack{" +
                "array=" + array +
                ", size=" + getSize() +
                '}';
    }
}
